package com.gui;

import java.awt.Component;
import java.awt.Dimension;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;

import javax.imageio.ImageIO;
import javax.swing.BorderFactory;
import javax.swing.Box;
import javax.swing.JPanel;
import javax.swing.border.TitledBorder;

public class UtilsGUI {

	
	static public Component createSpacing(int space) {
		return Box.createRigidArea(new Dimension(space, space));
	}
	
	 /**
	 * Creates a panel with titled border. 
	 * @param title String
	 * @param dim Dimension
	 * @return Component
	 * */
	static public Component makeBorderPanel (String title, Dimension dim) {
		JPanel panel = new JPanel();
		panel.setPreferredSize(dim);
		panel.setSize(dim);
		TitledBorder titled;
		titled = BorderFactory.createTitledBorder(title);
		panel.setBorder(titled);
		return panel;
	}
	
	/**
	 * Creates a panel with titled border.
	 * @param panel JPanel 
	 * @param title String
	 * @param dim Dimension 
	 * */
	static public void makeBorderPanel (JPanel panel, String title, Dimension dim) {
		panel.setPreferredSize(dim);
		TitledBorder titled;
		titled = BorderFactory.createTitledBorder(title);
		panel.setBorder(titled);
	}
	
	/**
	 * Loads an image from a file.
	 * @param imgFile File
	 * @return {@link BufferedImage}
	 * */
	static public BufferedImage loadImage(File imgFile) {
        BufferedImage img = null;
        try {
            img =  ImageIO.read(imgFile);
            System.out.println("Image readed");
        } catch (IOException e) {
        	System.out.println("Image not found: " + imgFile.getName());
        }
        return img;
    }
	
	/**
	 * Loads an image from a file.
	 * @param path String containing the image path.
	 * @return {@link BufferedImage}
	 * */
	static public BufferedImage loadImage(String path) {
        BufferedImage img = null;
        File imgFile = new File (path);
        try {
            img =  ImageIO.read(imgFile);
            System.out.println("Image readed");
        } catch (IOException e) {
        	System.out.println("Image not found: " + imgFile.getName());
        }
        return img;
    }
	
}
